/*
 * 设备管理列表


 */
<style lang="less" rel="stylesheet/less" type="text/less" >
.v-customer-banner-index{
	.ivu-table-column-center{
		padding: 5px 0;
	}
	.ivu-table-cell{
		padding-left: 10px;
		padding-right: 10px;
	}
	.info-banner{
        display: flex;
        justify-content: center;
		white-space: nowrap;
		padding: 5px 0;
	}
	.info-thumb{
		width: 120px;
		height: 120px;
		cursor: pointer;
		display: flex;
		align-items: center;
		img{
			width: 100%;
		}
	}
	.deleted, .hot, .new, .sale {
		cursor: pointer;
	}
}
</style>
<template>
	<div class="v-customer-banner-index">

		<Table
			:columns="columns"
			:loading="loading"
			:data="device_index"
			:height="tableHeight()"
			border
			class="personal-scrollbar"
			@on-sort-change="sortable"/>
	</div>
</template>

<script>
import { Tag, Button } from 'iview';
import showPictureMixin from 'src/views/mixins/showPictureMixin';
import { computedTableHeight } from 'src/views/mixins/computedTableHeight';

export default {
	name: 'BannerIndex',
	mixins: [showPictureMixin, computedTableHeight],
	props: {
		loading: {
			type: Boolean,
			default() {
				return false;
			},
		},
		device_index: {
			type: Array,
			default() {
				return [];
			},
		},
	},
	data() {
		return {
			columns: [
				{
					title: this.$t('lightingprese.name'),
					key: 'name',
					align: 'center',
					render: (h, { row }) => <div> { row.name || '-' } </div>,
				},
				{
					title: this.$t('lightingprese.logo'),
					key: 'logo',
					align: 'center',
					render: (h, { row }) => <div>{
						row.logo
							? <img src={ row.logo} alt={this.$t('common.none')} width="150px" height="100px"/>
							: this.$t('common.none')
					}
					</div>,
				},
			     {
					title: this.$t('home.device'),
					key: 'preset',
					align: 'center',
					render: (h, { row }) => <div> { row.preset.customize_json || '-' } </div>,
				},
				    {
					title: this.$t('lightingprese.color_temperature'),
					key: 'color_temperature',
					align: 'center',
					render: (h, { row }) => <div> { row.color_temperature} </div>,
				},
				    {
					title: this.$t('lightingprese.luminance'),
					key: 'luminance',
					align: 'center',
					render: (h, { row }) => <div> { row.luminance} </div>,
				},
				{
					title: this.$t('banner.priority'),
					key: 'sort_order',
					align: 'center',
					width: 90,
					sortable: 'custom',
					render: (h, { row }) => <div> { String(row.sort_order) || '-' } </div>,
				},
               	{
					title: this.$t('category.is_show'),
					key: 'is_show',
					width: 70,
					align: 'center',
					render: (h, { row }) => {
						let is_showText =<div>是</div>;
						let no_showText =<div>否</div>
						if (row.is_show==0) {
							return no_showText
						}else{
							return is_showText
						}
						
					},
				},

				{
					title: this.$t('common.operation'),
					align: 'center',
					width: 140,
					render: (h, { row }) => (
						<div>
							<Button name="index__edit" size="small" style={{ marginRight: '5px' }} on-click={() => { this.$emit('edit', row); }} type="primary">
								{ this.$t('common.edit') }
							</Button>
							<Button name="index__delete" size="small" style={{ marginRight: '5px' }} on-click={() => { this.$emit('delete', row.id); }} type="error">
								{ this.$t('common.delete') }
							</Button>
						</div>),
				},
			],
		};
	},
	methods: {

		/**
         * 排序的回调
         * @param  {Object} param {对应列的属性对象,里面包含了column列属性，key值，order排序字段}
         * @return {undefined}
         */
		sortable(param) {
			const search_param = {
				sort_column: param.key,

				sort_by: param.order === 'normal' ? '' : param.order,
			};

			this.$emit('sort', search_param);
		},

	},
};
</script>
